﻿
module("FallingJ.init")
test("FallingJ init", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingJ = new tetris.FallingJ(x, y, color);
    equal(5, fallingJ.center.x, "CenterX of FallingJ is set");
    equal(6, fallingJ.center.y, "CenterY of FallingJ is set");

    var relativeBody="";
    for (var i = 0; i < fallingJ._relativeBody.length; i++) {
        relativeBody += fallingJ._relativeBody[i].coordinate.toString() + " ";
    }
    equal("(0,-1) (0,0) (0,1) (1,-1) ", relativeBody, "CenterY of FallingJ is set");

    var body= "";
    for (var i = 0; i < fallingJ.getBody.length; i++) {
        body += fallingJ.getBody[i].coordinate.toString() + " ";
    }
    equal("(5,5) (5,6) (5,7) (6,5) ", body, "CenterY of FallingJ is set");
});

test("FallingJ moveTo", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingJ = new tetris.FallingJ(x, y, color);
    fallingJ.moveTo(7, 8);

    deepEqual(7, fallingJ.center.x, "CenterX of FallingJ is set to new x");
    equal(8, fallingJ.center.y, "CenterY of FallingJ is set to new y");

    var relativeBody = "";
    for (var i = 0; i < fallingJ._relativeBody.length; i++) {
        relativeBody += fallingJ._relativeBody[i].coordinate.toString() + " ";
    }
    equal("(0,-1) (0,0) (0,1) (1,-1) ", relativeBody, "CenterY of FallingJ is set");

    var body = "";
    for (var i = 0; i < fallingJ.getBody.length; i++) {
        body += fallingJ.getBody[i].coordinate.toString() + " ";
    }
    equal("(7,7) (7,8) (7,9) (8,7) ", body, "CenterY of FallingJ is set");
});

test("FallingJ moveRight", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingJ = new tetris.FallingJ(x, y, color);
    fallingJ.moveRight(); 
    deepEqual(6, fallingJ.center.x, "CenterX of FallingJ is set to x+1");
    equal(8, fallingJ.center.y, "CenterY of FallingJ is same");
});

test("FallingJ moveLeft", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingJ = new tetris.FallingJ(x, y, color);
    fallingJ.moveLeft();
    deepEqual(4, fallingJ.center.x, "CenterX of FallingJ is set to x-1");
    equal(8, fallingJ.center.y, "CenterY of FallingJ is same");
});

test("FallingJ moveUp", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingJ = new tetris.FallingJ(x, y, color);
    fallingJ.moveUp();
    equal(5, fallingJ.center.x, "CenterX of FallingJ is same");
    equal(7, fallingJ.center.y, "CenterY of FallingJ is set to y-1");
});

test("FallingJ moveDown", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingJ = new tetris.FallingJ(x, y, color);
    fallingJ.moveDown();
    equal(5, fallingJ.center.x, "CenterX of FallingJ is same");
    equal(9, fallingJ.center.y, "CenterY of FallingJ is set to y+1");
});

test("FallingJ rotate", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingJ = new tetris.FallingJ(x, y, color);
    fallingJ.rotate();
    equal(90, fallingJ.rotation, "Rotation of FallingJ is set to 90");
});

test("FallingJ rotate twice", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingJ = new tetris.FallingJ(x, y, color);
    fallingJ.rotate();
    equal(90, fallingJ.rotation, "Rotation of FallingJ is set to 90");
    fallingJ.rotate();
    equal(180, fallingJ.rotation, "Rotation of FallingJ is set to 180");
});

test("FallingJ rotateBack", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingJ = new tetris.FallingJ(x, y, color);
    fallingJ.rotateBack();
    equal(270, fallingJ.rotation, "Rotation of FallingJ is set to 270");   
});

test("FallingJ rotateTo", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingJ = new tetris.FallingJ(x, y, color);
    fallingJ.rotateTo(180);
    equal(180, fallingJ.rotation, "Rotation of FallingJ is set to 180");
});

